package com.example.pt.repository;

import com.example.pt.entity.Peer;
import com.example.pt.entity.Torrent;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.Instant;
import java.util.List;
import java.util.Optional;

public interface PeerRepository extends JpaRepository<Peer, Long> {

    @Query(value = """
        SELECT t.* 
        FROM torrent t 
        JOIN peer p ON t.id = p.torrent_id 
        WHERE p.user_id = :userId
    """, nativeQuery = true)

    List<Torrent> findDownloadsByUserId(@Param("userId") Long userId);
}
